import axios from "axios";

axios.defaults.baseURL = 'http://192.168.0.109:8088'
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
let token_name = 'authorization'
axios.$TOKEN_HEADER = token_name

axios.interceptors.request.use(req => {
  req.headers[token_name] = localStorage.getItem('token')
  return req;
}, err => {
  return Promise.reject(err)
})

axios.interceptors.response.use(res => {
  if (res.data.code === 408) {
    localStorage.removeItem('token')
    localStorage.removeItem('username')
  }
  return res;
}, err => {
  return Promise.reject(err)
})
export default axios
